package com.longxi.tianjintianbao.ui.presenter.houseinspection;

import android.support.v4.view.ViewPager;

import com.flyco.tablayout.listener.OnTabSelectListener;
import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.adapter.HomeInspectionPagerAdapter;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.base.BasePresenter;
import com.longxi.tianjintianbao.ui.view.houseinspection.IHouseInspectionAtView;
import com.longxi.tianjintianbao.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

public class HomeInspectionAtPresenter extends BasePresenter<IHouseInspectionAtView> {

    private HomeInspectionPagerAdapter approvalPagerAdapter;
    private String[] mTitles_3 = {"入住验房", "退住验房", "资产赔偿单"};

    /**
     * 入住验房
     */
    private void initRuZhuYanFang() {
        getView().getTabLayout().setTabData(mTitles_3);
        initViewPager();
    }

    public HomeInspectionAtPresenter(BaseActivity context) {
        super(context);
    }

    public void setBar() {
        mContext.setTvLeft(MyUtils.getString(R.string.home));
        initRuZhuYanFang();
    }

    public void initViewPager(){
        approvalPagerAdapter = new HomeInspectionPagerAdapter(mContext.getSupportFragmentManager(), mTitles_3);
        getView().getViewPager().setAdapter(approvalPagerAdapter);
        getView().getViewPager().setOffscreenPageLimit(mTitles_3.length - 1);
    }

    public void initListener() {
        getView().getTabLayout().setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                getView().getViewPager().setCurrentItem(position);
                mContext.setTitle(mTitles_3[position]);
            }

            @Override
            public void onTabReselect(int position) {

            }
        });

        getView().getViewPager().addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                getView().getTabLayout().setCurrentTab(position);
                mContext.setTitle(mTitles_3[position]);
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });

        mContext.setTitle(mTitles_3[0]);
        getView().getViewPager().setCurrentItem(0);
    }

    @Override
    public void detachView() {
        super.detachView();
        this.approvalPagerAdapter = null;
    }
}
